import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:hc_ui/config/hc_customer_config.dart';
import 'package:hc_ui/config/hc_default_theme_config.dart';
import 'package:hc_ui/theme/hc_base_theme.dart';
import 'package:hc_ui/theme/hc_common_theme.dart';

class HcDialogTheme extends HcBaseTheme<HcDialogTheme> {
  double? _width;
  Color? _background;
  double? _radius;
  double? _iconSize;
  double? _buttonSpacing;
  Color? _iconColor;
  Color? _borderColor;
  double? _borderWidth;
  TextAlign? _titleTextAlign;
  TextStyle? _titleTextStyle;
  TextAlign? _contentTextAlign;
  TextStyle? _contentTextStyle;
  TextAlign? _warningTextAlign;
  TextStyle? _warningTextStyle;
  double? _mainAxisSpacing;
  EdgeInsets? _widgetPadding;
  EdgeInsets? _iconMargin;
  EdgeInsets? _titleMargin;
  EdgeInsets? _titlePadding;
  EdgeInsets? _contentPadding;
  EdgeInsets? _warningPadding;
  EdgeInsets? _warningMargin;
  EdgeInsets? _buttonListPadding;

  HcDialogTheme({
    double? width,
    Color? background,
    Color? iconColor,
    Color? borderColor,
    double? borderWith,
    double? radius,
    double? iconSize,
    double? buttonSpacing,
    TextAlign? titleTextAlign,
    TextStyle? titleTextStyle,
    double? mainAxisSpacing,
    TextStyle? contentTextStyle,
    TextAlign? contentTextAlign,
    TextStyle? warningTextStyle,
    TextAlign? warningTextAlign,
    EdgeInsets? widgetPadding,
    EdgeInsets? iconMargin,
    EdgeInsets? titleMargin,
    EdgeInsets? titlePadding,
    EdgeInsets? contentPadding,
    EdgeInsets? warningPadding,
    EdgeInsets? warningMargin,
    EdgeInsets? buttonListPadding,
  })  : _width = width,
        _iconColor = iconColor,
        _iconSize = iconSize,
        _background = background,
        _borderColor = borderColor,
        _borderWidth = borderWith,
        _radius = radius,
        _buttonSpacing = buttonSpacing,
        _titleTextAlign = titleTextAlign,
        _titleTextStyle = titleTextStyle,
        _contentTextAlign = contentTextAlign,
        _contentTextStyle = contentTextStyle,
        _warningTextAlign = warningTextAlign,
        _warningTextStyle = warningTextStyle,
        _widgetPadding = widgetPadding,
        _iconMargin = iconMargin,
        _titleMargin = titleMargin,
        _titlePadding = titlePadding,
        _contentPadding = contentPadding,
        _buttonListPadding = buttonListPadding,
        _warningPadding = warningPadding,
        _warningMargin = warningMargin,
        _mainAxisSpacing = mainAxisSpacing;

  @override
  initTheme({HcCommonTheme? tempTheme}) {
    super.initTheme(tempTheme: tempTheme);
    HcDialogTheme dialogTheme = HcCustomerConfig().allTheme.dialogTheme;
    _width ??= dialogTheme.width;
    _iconSize ??= commonTheme.iconSizeXxl;
    _background ??= commonTheme.fillWidgetColor;
    _borderColor ??= commonTheme.borderColor;
    _borderWidth ??= commonTheme.lineBase;
    _radius ??= commonTheme.radiusBase;
    _buttonSpacing ??= commonTheme.hSpacingXs;
    _titleTextAlign ??= dialogTheme.titleTextAlign;
    _titleTextStyle ??= dialogTheme.titleTextStyle.merge(TextStyle(
            color: commonTheme.textTitleColor,
            fontSize: commonTheme.fontSizeTitle)
        .merge(_titleTextStyle));
    _mainAxisSpacing ??= dialogTheme.mainAxisSpacing;
    _contentTextAlign ??= dialogTheme.contentTextAlign;
    _contentTextStyle ??= dialogTheme.contentTextStyle.merge(TextStyle(
            color: commonTheme.textBaseColor,
            fontSize: commonTheme.fontSizeBase)
        .merge(_contentTextStyle));
    _warningTextAlign ??= dialogTheme.warningTextAlign;
    _warningTextStyle ??= dialogTheme.warningTextStyle.merge(TextStyle(
            fontSize: commonTheme.fontSizeBase, color: commonTheme.warningColor)
        .merge(_warningTextStyle));
    _widgetPadding ??= EdgeInsets.symmetric(vertical: commonTheme.vSpacingXxl);
    _iconMargin ??= EdgeInsets.only(
      bottom: commonTheme.vSpacingXxl,
    );
    _titleMargin ??= EdgeInsets.only(bottom: commonTheme.vSpacingXs);
    _titlePadding ??= EdgeInsets.symmetric(
        horizontal: commonTheme.hSpacingPage, vertical: 0.0);
    _contentPadding ??=
        EdgeInsets.symmetric(horizontal: commonTheme.hSpacingPage);
    _warningPadding ??=
        EdgeInsets.symmetric(horizontal: commonTheme.hSpacingPage);
    _warningMargin ??= EdgeInsets.only(top: commonTheme.hSpacingSm);

    _buttonListPadding ??= EdgeInsets.only(
        left: commonTheme.hSpacingPage,
        right: commonTheme.hSpacingPage,
        bottom: commonTheme.vSpacingXxl);
  }

  @override
  HcDialogTheme merge(HcDialogTheme? value) {
    if (value == null) return this;
    return copyWith(
      width: value._width,
      iconColor: value._iconColor,
      borderColor: value._borderColor,
      borderWidth: value._borderWidth,
      iconSize: value._iconSize,
      buttonSpacing: value._buttonSpacing,
      background: value._background,
      radius: value._radius,
      titleTextAlign: value._titleTextAlign,
      titleTextStyle: titleTextStyle.merge(value._titleTextStyle),
      mainAxisSpacing: value._mainAxisSpacing,
      contentTextAlign: value._contentTextAlign,
      contentTextStyle: contentTextStyle.merge(value._contentTextStyle),
      warningTextAlign: value._warningTextAlign,
      warningTextStyle: warningTextStyle.merge(value._warningTextStyle),
      widgetPadding: value._widgetPadding,
      iconMargin: value._iconMargin,
      titleMargin: value._titleMargin,
      titlePadding: value._titlePadding,
      contentPadding: value._contentPadding,
      warningPadding: value._warningPadding,
      warningMargin: value._warningMargin,
      buttonListPadding: value._buttonListPadding,
    );
  }

  copyWith({
    double? width,
    Color? background,
    Color? iconColor,
    Color? borderColor,
    double? borderWidth,
    double? iconSize,
    double? radius,
    double? buttonSpacing,
    TextAlign? titleTextAlign,
    TextStyle? titleTextStyle,
    EdgeInsets? padding,
    double? mainAxisSpacing,
    TextStyle? contentTextStyle,
    TextAlign? contentTextAlign,
    TextAlign? warningTextAlign,
    TextStyle? warningTextStyle,
    EdgeInsets? widgetPadding,
    EdgeInsets? iconMargin,
    EdgeInsets? titleMargin,
    EdgeInsets? titlePadding,
    EdgeInsets? contentPadding,
    EdgeInsets? warningPadding,
    EdgeInsets? warningMargin,
    EdgeInsets? buttonListPadding,
  }) {
    return HcDialogTheme(
      width: width ?? _width,
      background: background ?? _background,
      borderColor: borderColor ?? _borderColor,
      borderWith: borderWidth ?? _borderWidth,
      radius: radius ?? _radius,
      buttonSpacing: buttonSpacing ?? _buttonSpacing,
      iconSize: iconSize ?? _iconSize,
      iconColor: iconColor ?? _iconColor,
      titleTextAlign: titleTextAlign ?? _titleTextAlign,
      titleTextStyle: titleTextStyle ?? _titleTextStyle,
      mainAxisSpacing: mainAxisSpacing ?? _mainAxisSpacing,
      contentTextStyle: contentTextStyle ?? _contentTextStyle,
      contentTextAlign: contentTextAlign ?? _contentTextAlign,
      warningTextAlign: warningTextAlign ?? _warningTextAlign,
      warningTextStyle: warningTextStyle ?? _warningTextStyle,
      widgetPadding: widgetPadding ?? _widgetPadding,
      warningMargin: warningMargin ?? _warningMargin,
      warningPadding: warningPadding ?? _warningPadding,
      iconMargin: iconMargin ?? _iconMargin,
      titlePadding: titlePadding ?? _titlePadding,
      titleMargin: titleMargin ?? _titleMargin,
      contentPadding: contentPadding ?? _contentPadding,

      buttonListPadding: buttonListPadding ?? _buttonListPadding,
    );
  }

  double get width => _width ?? HcDefaultThemeConfig.defaultDialogTheme.width;

  Color get background =>
      _background ?? HcDefaultThemeConfig.defaultDialogTheme.background;

  double get radius =>
      _radius ?? HcDefaultThemeConfig.defaultDialogTheme.radius;

  TextAlign get titleTextAlign =>
      _titleTextAlign ?? HcDefaultThemeConfig.defaultDialogTheme.titleTextAlign;

  TextStyle get titleTextStyle =>
      _titleTextStyle ?? HcDefaultThemeConfig.defaultDialogTheme.titleTextStyle;

  double get mainAxisSpacing =>
      _mainAxisSpacing ??
      HcDefaultThemeConfig.defaultDialogTheme.mainAxisSpacing;

  TextAlign get contentTextAlign =>
      _contentTextAlign ??
      HcDefaultThemeConfig.defaultDialogTheme.contentTextAlign;

  TextStyle get contentTextStyle =>
      _contentTextStyle ??
      HcDefaultThemeConfig.defaultDialogTheme.contentTextStyle;

  TextAlign get warningTextAlign =>
      _warningTextAlign ??
      HcDefaultThemeConfig.defaultDialogTheme.warningTextAlign;

  TextStyle get warningTextStyle =>
      _warningTextStyle ??
      HcDefaultThemeConfig.defaultDialogTheme.warningTextStyle;

  EdgeInsets get contentPadding =>
      _contentPadding ?? HcDefaultThemeConfig.defaultDialogTheme.contentPadding;

  EdgeInsets get warningPadding =>
      _warningPadding ?? HcDefaultThemeConfig.defaultDialogTheme.warningPadding;

  EdgeInsets get warningMargin =>
      _warningMargin ?? HcDefaultThemeConfig.defaultDialogTheme.warningMargin;

  EdgeInsets get titleMargin =>
      _titleMargin ?? HcDefaultThemeConfig.defaultDialogTheme.titleMargin;

  EdgeInsets get widgetPadding =>
      _widgetPadding ?? HcDefaultThemeConfig.defaultDialogTheme.widgetPadding;

  EdgeInsets get iconMargin =>
      _iconMargin ?? HcDefaultThemeConfig.defaultDialogTheme.iconMargin;

  EdgeInsets get titlePadding =>
      _titlePadding ?? HcDefaultThemeConfig.defaultDialogTheme.titlePadding;

  EdgeInsets get buttonListPadding =>
      _buttonListPadding ??
      HcDefaultThemeConfig.defaultDialogTheme.buttonListPadding;



  double get iconSize =>
      _iconSize ?? HcDefaultThemeConfig.defaultDialogTheme.iconSize;

  Color get iconColor =>
      _iconColor ?? HcDefaultThemeConfig.defaultDialogTheme.iconColor;

  double get borderWidth =>
      _borderWidth ?? HcDefaultThemeConfig.defaultDialogTheme.borderWidth;

  Color get borderColor =>
      _borderColor ?? HcDefaultThemeConfig.defaultDialogTheme.borderColor;

  double get buttonSpacing =>
      _buttonSpacing ?? HcDefaultThemeConfig.defaultDialogTheme.buttonSpacing;
}
